"""
令Di是i子树分配的权值和则
Di = 1 + max(DL, DR)
"""
class Solution:
    def getTreeSum(self , tree):
        
        def dfs(root):
            lsum, rsum = 0, 0
            if root.left: lsum = dfs(root.left)
            if root.right: rsum = dfs(root.right)
            ss = max(lsum, rsum)
            return (ss + ss + 1)
        
        return dfs(tree) % (1000000000 + 7)